﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;
using MvcWinesSample.DAL.Models;

namespace MvcWinesSample.ViewModels
{
    public class WineDetails : ViewModelBase<Wine>
    {
        //due to backbone contraint TODO: OVERRIDE js METHOD
        public int id { get; set; }
        public string name { get; set; }
        public string year { get; set; }
        public string grapes { get; set; }
        public string region { get; set; }
        public string country { get; set; }
        public string description { get; set; }
        public string picture { get; set; }

        static WineDetails()
        {
        }

        public WineDetails(){}

        public WineDetails(Wine source)
        {
            id = source.Id;
            name = source.Name;
            year = source.Year;
            grapes = source.Grapes;
            region = source.Region;
            country = source.Country;
            description = source.Description;
            picture = source.Picture;
        }

        public static explicit operator WineDetails(Wine source)
        {
            Mapper.CreateMap<Wine, WineDetails>();
            return Mapper.Map< Wine,WineDetails>(source);
        }

        public static explicit operator Wine(WineDetails source)
        {
            Mapper.CreateMap<WineDetails, Wine>();
            return Mapper.Map<WineDetails, Wine>(source);
        }

        public static List<WineDetails> From(List<Wine> source)
        {
            var result = new List<WineDetails>(source.Count);
            result.AddRange(source.Select(wine => (WineDetails)wine));

            return result;
        }
    }
}